<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
/*
	[天生创想] (C)2008-2011 515158 Inc.
	This is NOT a freeware, use is subject to license terms
    URL:http://www.515158.com/
*/

get_config_keytable("book_read");
function get_inc_user_types($fid=0)
{
    global $db;
	$html='';
	$query = $db->query("SELECT title FROM ".DB_TABLEPRE."book_type where id='".$fid."' ORDER BY id desc limit 0,1");
	while ($rowuser = $db->fetch_array($query)) {
	$html .= $rowuser[title];
	}
	return $html;
}



empty($do) && $do = 'list';
if ($do == 'list') {
	//列表信息 
	$wheresql = '';
	$page = max(1, getGP('page','G','int'));
	$pagesize = 20;
	$offset = ($page - 1) * $pagesize;
	$url = 'admin.php?ac=indexsearch&fileurl=book';

	if ($keyword = getGP('keyword','G')) {
		$wheresql .= " AND bookname LIKE '%$keyword%'";
		$url .= '&keyword='.rawurlencode($keyword);
	}
	//时间
	$vstartdate = getGP('vstartdate','G');
	$venddate = getGP('venddate','G');
	if ($vstartdate!='' && $venddate!='') {
	$wheresql .= " AND (date>='".$vstartdate."' and date<='".$venddate."')";
	$url .= '&vstartdate='.$vstartdate.'&venddate='.$venddate;
	}
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."book WHERE 1 $wheresql");
     $sql = "SELECT * FROM ".DB_TABLEPRE."book WHERE 1 $wheresql ORDER BY id desc LIMIT $offset, $pagesize";
	$result = $db->fetch_all($sql);

	include_once('template/indexsearch.php');

} elseif ($do == 'save') {
	$id = getGP('id','G','int');
	//读取数据
	$r = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."book where id='".$id."' ORDER BY id desc limit 0,1");
	$booknumber = $r[bookumber];
	$bookname = $r[bookname];
	$appperson = $_USER->id;
	$examperson = '0';
	$appdate =get_date('Y-m-d H:i:s',PHP_TIME);
	$type ='1';
	$date =get_date('Y-m-d H:i:s',PHP_TIME);
	$book_read = array(
		'bookid' => $id,
		'booknumber' => $booknumber,
		'bookname' => $bookname,
		'appperson' => $appperson,
		'appdate' => $appdate,
		'type' => $type,
		'date' => $date
	);
	$book = array(
		'type' => $type
	);
	//写入主表信息
	insert_db('book_read',$book_read);
	$content=$booknumber.get_inc_log(1).$bookname.get_inc_log(1).$appperson.get_inc_log(1).$appdate.get_inc_log(1).$type;
	$title='图书借阅';
	get_oa_log_dbadd($id,$content,$title,22,$_USER->id);
	update_db('book',$book, array('id' => $id));
	//echo "ok";
	//exit;
	
	
	
	
	
    goto_page('admin.php?ac=file_read&type=1&fileurl=book');

}
?>